unit MainUn;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,GetConf, Grids, Buttons, ExtCtrls;

type
  TFuedit = class(TForm)
    UnitBox: TListBox;
    EditName: TEdit;
    EditAttack: TEdit;
    EditDefence: TEdit;
    EditMove: TEdit;
    EditVision: TEdit;
    EditCost: TEdit;
    EditAvtonom: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    EditTargets: TEdit;
    Label8: TLabel;
    Button1: TButton;
    SpeedButton1: TSpeedButton;
    Ul1: TImageList;
    icim: TImage;
    il1: TImageList;
    Procedure FillUnit(n:integer);
    Procedure SetUnit(n:integer);
    procedure FormCreate(Sender: TObject);
    procedure UnitBoxClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure EditNameKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditAttackKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditDefenceKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditMoveKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditVisionKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditCostKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EditAvtonomKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure UnitBoxKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Fuedit: TFuedit;
implementation

uses ue_grid,ue_def;

{$R *.DFM}

Procedure TFuedit.fillunit;
var
 ts:String;
 i:integer;
begin
 EditName.text:=conf.cfgs[n].name;
 EditAttack.text:=inttostr(conf.cfgs[n].atack);
 EditDefence.text:=inttostr(conf.cfgs[n].defence);
 Editmove.text:=inttostr(conf.cfgs[n].move);
 Editvision.text:=inttostr(conf.cfgs[n].vision);
 EditCost.text:=inttostr(conf.cfgs[n].cost);
 EditAvtonom.text:=inttostr(conf.cfgs[n].FuelAmmo);
 ts:='';
 for i:=0 to 14 do
  if conf.cfgs[n].targets[i] then ts:=ts+'1' else ts:=ts+'0';
 EditTargets.text:=ts;
 icim.canvas.brush.color:=clbtnface;
 icim.canvas.FillRect(rect(0,0,29,29));
 ul1.Draw(icim.canvas,0,0,n);
 icim.refresh;
end;

Procedure TFuedit.SetUnit;
var
 i:integer;
 ts:string;
begin
 conf.cfgs[n].name:=EditName.text;
 conf.cfgs[n].atack:=strtoint(EditAttack.text);
 conf.cfgs[n].defence:=strtoint(EditDefence.text);
 conf.cfgs[n].move:=strtoint(Editmove.text);
 conf.cfgs[n].vision:=strtoint(Editvision.text);
 conf.cfgs[n].cost:=strtoint(EditCost.text);
 conf.cfgs[n].FuelAmmo:=strtoint(EditAvtonom.text);
 ts:=edittargets.text;
 for i:=0 to 14 do
  if ts[i+1]='1' then conf.cfgs[n].targets[i]:=true else
   conf.cfgs[n].targets[i]:=false;
 unitbox.Items[n]:=editname.Text;
end;

procedure TFuedit.FormCreate(Sender: TObject);
var
 i:integer;
begin
  unitbox.clear;
  conf.loadfromfile('armies.dat');
  for i:=0 to 14 do unitbox.items.add(conf.cfgs[i].name);
  unitbox.ItemIndex:=0;
  loadunitsicon(ul1,il1);
  fillunit(unitbox.itemindex);
end;
procedure TFuedit.UnitBoxClick(Sender: TObject);
begin
 FillUnit(unitbox.itemindex);
 {icim.canvas.brush.color:=clbtnface;
 icim.canvas.FillRect(rect(0,0,29,29));
 ul1.Draw(icim.canvas,0,0,unitbox.itemindex);
 icim.refresh;}
end;

procedure TFuedit.Button1Click(Sender: TObject);
begin
 Setunit(unitbox.itemindex);
 conf.SaveToFile('armies.dat');
// conf.SaveToNewFile('d:\armies.dat');
end;


procedure TFuedit.EditNameKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then editattack.setfocus;
end;

procedure TFuedit.EditAttackKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then editdefence.setfocus;
end;

procedure TFuedit.EditDefenceKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then editmove.setfocus;
end;

procedure TFuedit.EditMoveKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then editvision.setfocus;
end;

procedure TFuedit.EditVisionKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then editcost.setfocus;
end;

procedure TFuedit.EditCostKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then editavtonom.setfocus;
end;

procedure TFuedit.EditAvtonomKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then edittargets.setfocus;
end;

procedure TFuedit.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 conf.SaveToFile('armies.dat');
end;

procedure TFuedit.UnitBoxKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then EditName.setfocus;
end;

procedure TFuedit.SpeedButton1Click(Sender: TObject);
var
 i:integer;
begin
 for i:=1 to 15 do begin
  grid.sg1.cells[1,i]:=inttostr(conf.cfgs[i-1].infantry.a);
  grid.sg1.cells[2,i]:=inttostr(conf.cfgs[i-1].gun.a);
  grid.sg1.cells[3,i]:=inttostr(conf.cfgs[i-1].AirGun.a);
  grid.sg1.cells[4,i]:=inttostr(conf.cfgs[i-1].Tank.a);
  grid.sg1.cells[5,i]:=inttostr(conf.cfgs[i-1].Supplies.a);
  grid.sg1.cells[6,i]:=inttostr(conf.cfgs[i-1].Fighter.a);
  grid.sg1.cells[7,i]:=inttostr(conf.cfgs[i-1].Bomber.a);
  grid.sg1.cells[8,i]:=inttostr(conf.cfgs[i-1].Submarine.a);
  grid.sg1.cells[9,i]:=inttostr(conf.cfgs[i-1].Transport.a);
  grid.sg1.cells[10,i]:=inttostr(conf.cfgs[i-1].Tanker.a);
  grid.sg1.cells[11,i]:=inttostr(conf.cfgs[i-1].Cruiser.a);
  grid.sg1.cells[12,i]:=inttostr(conf.cfgs[i-1].BattleShip.a);
  grid.sg1.cells[13,i]:=inttostr(conf.cfgs[i-1].Destroyer.a);
  grid.sg1.cells[14,i]:=inttostr(conf.cfgs[i-1].Deminer.a);
  grid.sg1.cells[15,i]:=inttostr(conf.cfgs[i-1].Carrier.a);

  grid.sg2.cells[1,i]:=inttostr(conf.cfgs[i-1].infantry.d);
  grid.sg2.cells[2,i]:=inttostr(conf.cfgs[i-1].gun.d);
  grid.sg2.cells[3,i]:=inttostr(conf.cfgs[i-1].AirGun.d);
  grid.sg2.cells[4,i]:=inttostr(conf.cfgs[i-1].Tank.d);
  grid.sg2.cells[5,i]:=inttostr(conf.cfgs[i-1].Supplies.d);
  grid.sg2.cells[6,i]:=inttostr(conf.cfgs[i-1].Fighter.d);
  grid.sg2.cells[7,i]:=inttostr(conf.cfgs[i-1].Bomber.d);
  grid.sg2.cells[8,i]:=inttostr(conf.cfgs[i-1].Submarine.d);
  grid.sg2.cells[9,i]:=inttostr(conf.cfgs[i-1].Transport.d);
  grid.sg2.cells[10,i]:=inttostr(conf.cfgs[i-1].Tanker.d);
  grid.sg2.cells[11,i]:=inttostr(conf.cfgs[i-1].Cruiser.d);
  grid.sg2.cells[12,i]:=inttostr(conf.cfgs[i-1].BattleShip.d);
  grid.sg2.cells[13,i]:=inttostr(conf.cfgs[i-1].Destroyer.d);
  grid.sg2.cells[14,i]:=inttostr(conf.cfgs[i-1].Deminer.d);
  grid.sg2.cells[15,i]:=inttostr(conf.cfgs[i-1].Carrier.d);

  grid.sgt1.cells[1,i]:=inttostr(conf.cfgs[i-1].forest.a);
  grid.sgt1.cells[2,i]:=inttostr(conf.cfgs[i-1].Mount.a);
  grid.sgt1.cells[3,i]:=inttostr(conf.cfgs[i-1].Desert.a);
  grid.sgt1.cells[4,i]:=inttostr(conf.cfgs[i-1].Arctic.a);
  grid.sgt1.cells[5,i]:=inttostr(conf.cfgs[i-1].Boloto.a);
  grid.sgt1.cells[6,i]:=inttostr(conf.cfgs[i-1].Town.a);

  grid.sgt2.cells[1,i]:=inttostr(conf.cfgs[i-1].forest.d);
  grid.sgt2.cells[2,i]:=inttostr(conf.cfgs[i-1].Mount.d);
  grid.sgt2.cells[3,i]:=inttostr(conf.cfgs[i-1].Desert.d);
  grid.sgt2.cells[4,i]:=inttostr(conf.cfgs[i-1].Arctic.d);
  grid.sgt2.cells[5,i]:=inttostr(conf.cfgs[i-1].Boloto.d);
  grid.sgt2.cells[6,i]:=inttostr(conf.cfgs[i-1].Town.d);

  grid.sgt3.cells[1,i]:=inttostr(conf.cfgs[i-1].forest.v);
  grid.sgt3.cells[2,i]:=inttostr(conf.cfgs[i-1].Mount.v);
  grid.sgt3.cells[3,i]:=inttostr(conf.cfgs[i-1].Desert.v);
  grid.sgt3.cells[4,i]:=inttostr(conf.cfgs[i-1].Arctic.v);
  grid.sgt3.cells[5,i]:=inttostr(conf.cfgs[i-1].Boloto.v);
  grid.sgt3.cells[6,i]:=inttostr(conf.cfgs[i-1].Town.v);


 end;
 grid.showmodal;
end;

end.
